package c.c.a;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.os.Build.VERSION;
import android.os.IBinder;
import android.os.IInterface;

public final class h1 implements d1 {
    public final d1 a;
    public p0<Boolean> b;

    public class a extends p0<Boolean> {
        public a(h1 h1Var) {
        }

        public Object a(Object[] objArr) {
            Object obj = Boolean.FALSE;
            boolean z = false;
            try {
                PackageInfo packageInfo = ((Context) objArr[0]).getPackageManager().getPackageInfo("com.heytap.openid", 0);
                if (packageInfo == null) {
                    return obj;
                }
                long longVersionCode;
                if (VERSION.SDK_INT >= 28) {
                    longVersionCode = packageInfo.getLongVersionCode();
                } else {
                    longVersionCode = (long) packageInfo.versionCode;
                }
                if (longVersionCode >= 1) {
                    z = true;
                }
                return Boolean.valueOf(z);
            } catch (Throwable th) {
                th.printStackTrace();
                return obj;
            }
        }
    }

    public class b implements c.c.a.k1.b<o0, String> {
        public final /* synthetic */ Context a;

        public b(Context context) {
            this.a = context;
        }

        public Object a(IBinder iBinder) {
            int i = c.c.a.o0.a.a;
            if (iBinder == null) {
                return null;
            }
            IInterface queryLocalInterface = iBinder.queryLocalInterface("com.heytap.openid.IOpenID");
            if (queryLocalInterface == null || !(queryLocalInterface instanceof o0)) {
                return new c.c.a.o0.a.a(iBinder);
            }
            return (o0) queryLocalInterface;
        }

        /* JADX WARNING: Removed duplicated region for block: B:29:? A:{SYNTHETIC, RETURN} */
        /* JADX WARNING: Removed duplicated region for block: B:26:0x006c  */
        /* JADX WARNING: Removed duplicated region for block: B:17:0x003a A:{Catch:{ Exception -> 0x0061 }} */
        /* JADX WARNING: Removed duplicated region for block: B:26:0x006c  */
        /* JADX WARNING: Removed duplicated region for block: B:29:? A:{SYNTHETIC, RETURN} */
        public java.lang.Object a(java.lang.Object r9) {
            /*
            r8 = this;
            r9 = (c.c.a.o0) r9;
            r0 = 0;
            if (r9 != 0) goto L_0x0007;
        L_0x0005:
            goto L_0x0078;
        L_0x0007:
            r1 = c.c.a.h1.this;
            r2 = r8.a;
            java.util.Objects.requireNonNull(r1);
            r1 = r2.getPackageManager();	 Catch:{ all -> 0x0021 }
            r2 = r2.getPackageName();	 Catch:{ all -> 0x0021 }
            r3 = 64;
            r1 = r1.getPackageInfo(r2, r3);	 Catch:{ all -> 0x0021 }
            if (r1 == 0) goto L_0x0025;
        L_0x001e:
            r1 = r1.signatures;	 Catch:{ all -> 0x0021 }
            goto L_0x0026;
        L_0x0021:
            r1 = move-exception;
            r1.printStackTrace();
        L_0x0025:
            r1 = r0;
        L_0x0026:
            if (r1 == 0) goto L_0x0065;
        L_0x0028:
            r2 = r1.length;
            if (r2 <= 0) goto L_0x0065;
        L_0x002b:
            r2 = 0;
            r1 = r1[r2];
            r1 = r1.toByteArray();
            r3 = "SHA1";
            r3 = java.security.MessageDigest.getInstance(r3);	 Catch:{ Exception -> 0x0061 }
            if (r3 == 0) goto L_0x0065;
        L_0x003a:
            r1 = r3.digest(r1);	 Catch:{ Exception -> 0x0061 }
            r3 = new java.lang.StringBuilder;	 Catch:{ Exception -> 0x0061 }
            r3.<init>();	 Catch:{ Exception -> 0x0061 }
            r4 = r1.length;	 Catch:{ Exception -> 0x0061 }
        L_0x0044:
            if (r2 >= r4) goto L_0x005c;
        L_0x0046:
            r5 = r1[r2];	 Catch:{ Exception -> 0x0061 }
            r5 = r5 & 255;
            r5 = r5 | 256;
            r5 = java.lang.Integer.toHexString(r5);	 Catch:{ Exception -> 0x0061 }
            r6 = 3;
            r7 = 1;
            r5 = r5.substring(r7, r6);	 Catch:{ Exception -> 0x0061 }
            r3.append(r5);	 Catch:{ Exception -> 0x0061 }
            r2 = r2 + 1;
            goto L_0x0044;
        L_0x005c:
            r1 = r3.toString();	 Catch:{ Exception -> 0x0061 }
            goto L_0x0066;
        L_0x0061:
            r1 = move-exception;
            r1.printStackTrace();
        L_0x0065:
            r1 = r0;
        L_0x0066:
            r2 = android.text.TextUtils.isEmpty(r1);
            if (r2 != 0) goto L_0x0078;
        L_0x006c:
            r0 = r8.a;
            r0 = r0.getPackageName();
            r2 = "OUID";
            r0 = r9.b0(r0, r1, r2);
        L_0x0078:
            return r0;
            */
            throw new UnsupportedOperationException("Method not decompiled: c.c.a.h1$b.a(java.lang.Object):java.lang.Object");
        }
    }

    public h1() {
        this.b = new a(this);
        this.a = null;
    }

    public boolean a(Context context) {
        if (context == null) {
            return false;
        }
        Boolean bool = (Boolean) this.b.b(context);
        if (this.a == null || bool.booleanValue()) {
            return bool.booleanValue();
        }
        return this.a.a(context);
    }

    public c.c.a.d1.a b(Context context) {
        if (this.a != null && !((Boolean) this.b.b(new Object[0])).booleanValue()) {
            return this.a.b(context);
        }
        Intent intent = new Intent();
        intent.setComponent(new ComponentName("com.heytap.openid", "com.heytap.openid.IdentifyService"));
        intent.setAction("action.com.heytap.openid.OPEN_ID_SERVICE");
        String str = (String) new k1(context, intent, new b(context)).a();
        c.c.a.d1.a aVar = new c.c.a.d1.a();
        aVar.a = str;
        return aVar;
    }

    public h1(d1 d1Var) {
        this.b = new a(this);
        this.a = d1Var;
    }
}
